package com.kkom1.tapeat;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import data_management.PatternDataManager;
import data_management.SettingData;

public class IntroActivity extends Activity {
	private Handler h;
	private SettingData sdata = SettingData.getInstance();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		//super.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_intro);
		
		h = new Handler();
		if (!new File(PatternDataManager.FILEPATH).exists()) {
			AlertDialog.Builder alert_confirm = new AlertDialog.Builder(this);
			alert_confirm
					.setMessage(R.string.msg_ask_SetLockScreen)
					.setCancelable(false)
					.setPositiveButton(R.string.bt_confirm,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									// 'YES'
									startService(new Intent(
											"com.kkom1.tapeat.services.lockservice"));
									SettingData.getInstance().setLock_on(true);
									h.postDelayed(irun, 1000);
								}
							})
					.setNegativeButton(R.string.bt_cancel,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									// 'No'
									h.postDelayed(irun, 1000);
									return;
								}
							});
			AlertDialog alert = alert_confirm.create();
			alert.show();
		}
		else {
			if(sdata.isLock_on()){
				startService(new Intent("com.kkom1.tapeat.services.lockservice"));
			}
			h.postDelayed(irun, 2000);
		}
	}

	Runnable irun = new Runnable(){
		public void run(){
			Intent i = new Intent(IntroActivity.this, MainActivity.class);
			
			startActivity(i);
			finish();
			overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
		}
	};

	
	public void onBackPressed(){
		super.onBackPressed();
		h.removeCallbacks(irun);
	}
}